
#import "SettingsViewController.h"
#import "PushSettingsViewController.h"
#import "HelpViewController.h"

@implementation SettingsViewController

//
// init
//
- (id)init
{
	//
	// call super
	//
	self																	= [super initWithStyle:UITableViewStyleGrouped];
	if(!self)
		return nil;
	
	//
	// setup title, image
	//
	self.title																= NSLocalizedStringFromTable(@"Settings", @"SettingsViewController", nil);
	self.tabBarItem.image													= [UIImage imageNamed:@"tab_icon_settings.png"];

	return self;
}

//
// dealloc
//
- (void)dealloc
{
	[super dealloc];
}

//
// get section count
//
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
{
	return 2;
}

//
// get row count
//
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
	return section == 0 ? 2 : 3;
}

//
// get title
//
- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section
{
	if(section == 0)
		return NSLocalizedStringFromTable(@"Settings", @"SettingsViewController", nil);
	
	return NSLocalizedStringFromTable(@"Legal", @"SettingsViewController", nil);
}

//
// get footer
//
- (NSString*)tableView:(UITableView*)tableView titleForFooterInSection:(NSInteger)section
{
	if(section == 0)
		return nil;
	
	return NSLocalizedStringFromTable(@"Author: tiamo@live.com\nAll rights reserved", @"SettingsViewController", nil);
}

//
// get cell
//
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
	UITableViewCell* theCell												= [tableView dequeueReusableCellWithIdentifier:@"d>"];
	if(!theCell)
		theCell																= [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"d>"] autorelease];
	
	if(indexPath.section == 0)
	{
		if(indexPath.row == 0)
			theCell.textLabel.text											= NSLocalizedStringFromTable(@"Push Settings", @"SettingViewController", nil);
		else
			theCell.textLabel.text											= NSLocalizedStringFromTable(@"Help", @"SettingViewController", nil);
	}
	else if(indexPath.row == 0)
		theCell.textLabel.text												= NSLocalizedStringFromTable(@"app-bits icons", @"SettingsViewController", nil);
	else if(indexPath.row == 1)
		theCell.textLabel.text												= NSLocalizedStringFromTable(@"DSActivityView", @"SettingsViewController", nil);
	else
		theCell.textLabel.text												= NSLocalizedStringFromTable(@"UIAlertView-Blocks", @"SettingsViewController", nil);

	theCell.accessoryType													= UITableViewCellAccessoryDisclosureIndicator;
	return theCell;
}

//
// select row
//
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
	if(indexPath.section == 0)
	{
		if(indexPath.row == 0)
		{
			PushSettingsViewController* pushSettingsViewController			= [[[PushSettingsViewController alloc] init] autorelease];
			[self.navigationController pushViewController:pushSettingsViewController animated:YES];
			return;
		}
	}
	
	UITableViewCell* theCell												= [tableView cellForRowAtIndexPath:indexPath];
	HelpViewController* helpViewController									= [[[HelpViewController alloc] init] autorelease];
	helpViewController.title												= theCell.textLabel.text;
	
	if(indexPath.section == 0)
		helpViewController.resoureFile										= @"help";
	else if(indexPath.row == 0)
		helpViewController.resoureFile										= @"app-bits";
	else if(indexPath.row == 1)
		helpViewController.resoureFile										= @"dsactivityview";
	else if(indexPath.row == 2)
		helpViewController.resoureFile										= @"uialertviewblocks";
	
	[self.navigationController pushViewController:helpViewController animated:YES];
}
@end